package com.cold.demo.template.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * 访问路径
 *          3.0以下的访问路径 http://.../swagger-ui.html?docExpansion=list
 *          3.0及以上的访问路径 http://.../swagger-ui/index.html?docExpansion=list
 * docExpansion参数说明：none(不展开) list(展开operations) full(全部展开)
 */
@SpringBootConfiguration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${server.port}")
    private int serverPort;


    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
//                .title("项目接口列表")
//                .description("当前使用端口号：" + serverPort)
//                .termsOfServiceUrl("https://swagger.io/")
//                .contact(new Contact("周", "", "378661553@qq.com"))
//                .version("3.0")
                .build();
    }
}
